<?php

use think\migration\Migrator;
use think\migration\db\Column;

class BasicRegion extends Migrator
{
    public function up()
    {
        $table = $this->table('basic_region');
        $table
            //step1:名称
            ->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '城市名称'])
            ->addColumn('parent_id', 'integer', ['limit' => 2, 'default' => '0', 'comment' => '级别|上一级ID，0为第一级'])
            ->addColumn('level', 'integer', ['limit' => 6, 'comment'=>'1第1级,2第2级'])
            ->addColumn('status', 'integer', ['limit' => 2, 'comment'=>'状态0关闭1开启'])

            //step2:网格经纬度,默认长治网格的经纬度
            ->addColumn('grid_start_longitude', 'string', ['limit' => 20, 'default' => '36.0', 'comment'=>'网格开始经度'])
            ->addColumn('grid_start_latitude', 'string', ['limit' => 20, 'default' => '112.7', 'comment' => '网格开始纬度'])
            ->addColumn('grid_end_longitude', 'string', ['limit' => 20, 'default' => '36.5', 'comment'=> '网格结束经度'])
            ->addColumn('grid_end_latitude', 'string', ['limit' => 20, 'default' => '113.3', 'comment' => '网格结束纬度'])
            ->addColumn('delete_time', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '软删除'])

            //主键
            ->addIndex(['name'])

            //注释
            ->setComment('基本信息 - 区域')

            //引擎
            ->setEngine('InnoDB')
            ->save();
    }

    public function down()
    {
        $this->table('basic_region')->drop();
    }
}
